<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>登录</title>  
    <%@ include file="top.jsp"%> 
    <script type="text/javascript" src="http://ip.chinaz.com/getip.aspx"></script>
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:150px;"></div>
            <div class="media media-y margin-big-bottom">           
            </div>         
            <div class="panel loginbox">
                <div class="text-center margin-big padding-big-top"><h1>文章管理中心</h1></div>
                <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="text" class="input input-big" name="faccount" id ="faccount" placeholder="登录账号"  />
                            <span class="icon icon-user margin-small"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="password" id = "fpword" class="input input-big" name="fpword" placeholder="登录密码"  />
                            <span class="icon icon-key margin-small"></span>
                        </div>
                    </div>
                     <div class="field field-icon-right">
                            <input type='checkbox' name='rember' id = "rember"/>记住我
                        </div>
                </div>
                <div style="padding:10px 30px;"><input type="button" id ="bt_login" class="button button-block bg-main text-big input-big" value="登录"></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
$(function(){
	 $("#bt_login").click(function(){
		 login(); 
	  });
	 
	 if ($.cookie("rmbUser") == "true") {
        $("#rember").attr("checked", true);
        $("#faccount").val($.cookie("userName"));
        $("#fpword").val($.cookie("passWord"));
    }
});
function login(){
	var fpword = $("#fpword").val();
	var faccount = $("#faccount").val();
	var rember = 0;
	if($("#rember").is(':checked')) {
		rember = 1;
	}
	if($.isNull(faccount)){
		$("#faccount").focus();
		layer.tips('请输入账户(邮箱)', '#faccount', {
			  tips: [4, '#FF5722']
			});
		return;
	}
	if($.isNull(fpword)){
		$("#fpword").focus();
		layer.tips('请输入密码', '#fpword', {
			  tips: [4, '#FF5722']
			});
		return;
	}
	var index = layer.load(2, {time: 10000}); //又换了种风格，并且设定最长等待10秒 
	$.ajax({
	    type: "post",
	    dataType: 'json',
	    url : "<%=basePath%>user/loginUser",   //提交的路径
	    data: { 
	    		fpword:fpword,
	    		faccount:faccount,
	    		rember:rember
	    	},
	    success:function(data){
	    	if (data.errorCode == 0) {
	    		if (rember == 1) {
	    	        $.cookie("rmbUser", "true", { expires: 7 }); // 存储一个带7天期限的 cookie
	    	        $.cookie("userName", faccount, { expires: 7 }); // 存储一个带7天期限的 cookie
	    	        $.cookie("passWord", fpword, { expires: 7 }); // 存储一个带7天期限的 cookie
	    	    }
	    	    else {
	    	        $.cookie("rmbUser", "false", { expires: -1 });        // 删除 cookie
	    	        $.cookie("userName", '', { expires: -1 });
	    	        $.cookie("passWord", '', { expires: -1 });
	    	    }
	    		window.location.href="<%=basePath%>index"; 
			}else{
				layer.msg(data.message, {icon: 5, offset: '10px'});
			};
			layer.close(index); 
		}
	});
	layer.close(index); 
}
</script>	
</body>
</html>